package net.begincode.controller;

import net.begincode.common.exception.BizException;
import net.begincode.enums.ParamResponseEnum;
import net.begincode.enums.UserResponseEnum;
import net.begincode.handler.UserHandler;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * Created by saber on 2017/9/22.
 */
@RequestMapping("login")
@Controller
public class UserController {

    private static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Resource
    private UserHandler userHandler;

    @RequestMapping("check")
    public String loginCheck(String mail ,String password){

        if(StringUtils.isNotBlank(mail) && StringUtils.isNotBlank(password)){
            throw new BizException(ParamResponseEnum.PARAM_NULL_ERROR);
        }
        if(!userHandler.login(mail,password)){
            throw new BizException(UserResponseEnum.USER_NULL_ERROR);
        }
        return "server";
    }


}
